package com.lzj.demo.design.chain;

import com.lzj.demo.design.common.ServerResult;
import com.lzj.demo.design.vo.OrderQueryVO;

public abstract class AbstractHandler {
    //责任链中的下一个对象
    private AbstractHandler nextHandler;

    /**
     * 责任链的下一个对象
     */
    public void setNextHandler(AbstractHandler nextHandler){
        this.nextHandler = nextHandler;
    }

    public AbstractHandler getNextHandler() {
        return nextHandler;
    }

    abstract ServerResult doFilter(OrderQueryVO filterRequest, ServerResult response);

    /**
     * 具体参数拦截逻辑,给子类去实现
     */
    public ServerResult filter(OrderQueryVO request, ServerResult response) {
        doFilter(request, response);
        if(response.checkNotSuccess()){
            return response;
        }
        if (getNextHandler() != null) {
            getNextHandler().filter(request, response);
        }
        return response;
    }
}
